package com.fanfanwang.ffw.app.fragment;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BaiduMap.OnMarkerClickListener;
import com.baidu.mapapi.map.BaiduMap.OnMarkerDragListener;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.InfoWindow;
import com.baidu.mapapi.map.InfoWindow.OnInfoWindowClickListener;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.Marker;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.MyLocationConfiguration;
import com.baidu.mapapi.map.MyLocationConfiguration.LocationMode;
import com.baidu.mapapi.map.MyLocationData;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.map.UiSettings;
import com.baidu.mapapi.model.LatLng;
import com.fanfanwang.ffw.app.AppConstant;
import com.fanfanwang.ffw.app.AppContext;
import com.fanfanwang.ffw.app.R;
import com.fanfanwang.ffw.app.asynctask.GetCityListAsyncTask;
import com.fanfanwang.ffw.app.asynctask.GetLengthListAsyncTask;
import com.fanfanwang.ffw.app.asynctask.GetParkListAsyncTask;
import com.fanfanwang.ffw.app.asynctask.GetparkingListAsyncTask;
import com.fanfanwang.ffw.app.base.BaseFragment;
import com.fanfanwang.ffw.app.bean.CityListBean;
import com.fanfanwang.ffw.app.bean.LengthListBean;
import com.fanfanwang.ffw.app.bean.ParkingListBean;
import com.fanfanwang.ffw.app.common.ToastAlone;
import com.fanfanwang.ffw.app.tools.SharedPreferencesUtil;
import com.fanfanwang.ffw.app.ui.home.SectionDetailAct;
import com.fanfanwang.ffw.app.ui.service.ServiceYuYueListAct;
import com.fanfanwang.ffw.app.widget.CommonTitleBar;
import com.fanfanwang.ffw.app.widget.expandlist.ExpandTabView;
import com.fanfanwang.ffw.app.widget.expandlist.ViewMiddle;
import com.fanfanwang.ffw.app.widget.expandlist.ViewRight;

/**
 * @author Administrator
 * 
 */
@SuppressLint("ValidFragment")
public class MainTingcheFragment extends BaseFragment {

	private CommonTitleBar mCommonTitleBar;
	private LayoutInflater inflater;
	/**
	 * 网络错误布局layout
	 */
	private LinearLayout llNetError;
	/**
	 * 网络错误显示图片
	 */
	private ImageView ivNetErrorReload;

	private ExpandTabView expandTabViewPianqu;
	private ArrayList<View> mViewArray = new ArrayList<View>();
	// private ViewLeft viewLeft;
	private ViewMiddle viewPianqu;
	private ViewRight viewJuli;

	/**
	 * 百度地图View
	 */
	private MapView mMapView;

	private UiSettings mUiSettings;

	private BaiduMap mBaiduMap;
	private InfoWindow mInfoWindow;

	// 定位相关
	LocationClient mLocClient;
	public MyLocationListenner myListener = new MyLocationListenner();
	private LocationMode mCurrentMode;
	private BitmapDescriptor mCurrentMarker;
	boolean isFirstLoc = true;// 是否首次定位
	private Button btnTingcheLocation;
	private TextView tvCurrentLocation;
	private RelativeLayout rlCurrentLocation;
	private Context context;

	// 初始化全局 bitmap 信息，不用时及时 recycle
	BitmapDescriptor bdA = BitmapDescriptorFactory
			.fromResource(R.drawable.map_mark);
	BitmapDescriptor bdGround = BitmapDescriptorFactory
			.fromResource(R.drawable.ground_overlay);

	/* 获取按距离查询的数据 */
	public static IGetLengthList iGetLengthList;
	public static IGetCityList iGetCityList;
	public static IGetSectionList iGetSectionList;
	private ArrayList<ParkingListBean> sectionLists;

	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View tingcheLayout = inflater.inflate(R.layout.fragment_tingche_layout,
				container, false);
		return tingcheLayout;
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onViewCreated(view, savedInstanceState);
		getActivity().getWindow().setFormat(PixelFormat.TRANSLUCENT);
		// TODO 因为baseFragment在onViewCreated里面已经调用了。所以继承的自动回调用
		// initView(view);
		// initData();
		// setListener();
	}

	public MainTingcheFragment(Context context) {
		super();
		inflater = LayoutInflater.from(context);
		this.context = context;
	}

	public static MainTingcheFragment getTingcheFragment(Context context) {
		MainTingcheFragment tingcheFragment = new MainTingcheFragment(context);
		return tingcheFragment;
	}

	@Override
	public void onResume() {
		// MapView的生命周期与Activity同步，当activity恢复时需调用MapView.onResume()
		// mMapView.setVisibility(View.VISIBLE);
		mMapView.onResume();
		super.onResume();
		if (!TextUtils.isEmpty(SharedPreferencesUtil.getInstance(getActivity())
				.getUserId())) {
			if (mCommonTitleBar != null) {

				mCommonTitleBar.setRightView(getString(R.string.yuyue_title),
						new OnClickListener() {

							@Override
							public void onClick(View v) {
								// TODO Auto-generated method stub
								Intent intent = new Intent(getActivity(),
										ServiceYuYueListAct.class);
								startActivity(intent);
							}
						});
			}
		}
	}

	@Override
	public void onPause() {
		// MapView的生命周期与Activity同步，当activity挂起时需调用MapView.onPause()
		// mMapView.setVisibility(View.INVISIBLE);
		mMapView.onPause();
		super.onPause();
	}

	@Override
	public void onDestroy() {
		// 退出时销毁定位
		if (mLocClient != null) {
			mLocClient.stop();
		}
		// 关闭定位图层
		mBaiduMap.setMyLocationEnabled(false);
		// MapView的生命周期与Activity同步，当activity销毁时需调用MapView.destroy()
		mMapView.onDestroy();
		mMapView = null;
		// 回收 bitmap 资源
		bdA.recycle();
		/*
		 * bdB.recycle(); bdC.recycle(); bdD.recycle(); bd.recycle();
		 */
		bdGround.recycle();
		super.onDestroy();
		// 退出时销毁定位

	}

	@Override
	public void initView(View view) {
		mCommonTitleBar = CommonTitleBar.getCommonTitleBar(getActivity());
		ivNetErrorReload = (ImageView) view.findViewById(R.id.ivNetErrorReload);
		llNetError = (LinearLayout) view.findViewById(R.id.llNetError);
		mMapView = (MapView) view.findViewById(R.id.bmapView);
		expandTabViewPianqu = (ExpandTabView) view
				.findViewById(R.id.expandtabViewPianqu);

		btnTingcheLocation = (Button) view
				.findViewById(R.id.btnTingcheLocation);
		tvCurrentLocation = (TextView) view
				.findViewById(R.id.tvCurrentLocation);
		rlCurrentLocation = (RelativeLayout) view
				.findViewById(R.id.rlCurrentLocation);
		rlCurrentLocation.setVisibility(View.GONE);
		// viewLeft = new ViewLeft(getActivity());
		setInterface();
		viewPianqu = new ViewMiddle(getActivity());
		viewJuli = new ViewRight(getActivity());
		sectionLists = new ArrayList<ParkingListBean>();
	}

	@Override
	public void initData() {
		if (AppContext.instance.isNetworkConnected()) {
			// 网络可用加载数据
			llNetError.setVisibility(View.GONE);
			//设置还有网络可用的时候才去初始化片区，否则不用，
			initVaulePianqu();
		} else {
			// 网络不可用显示网络错误页面
			llNetError.setVisibility(View.VISIBLE);
		}
		mCommonTitleBar.setCenterText(getString(R.string.main_tab_tingche));
		mBaiduMap = mMapView.getMap();
		mUiSettings = mBaiduMap.getUiSettings();
		setCompassEnable(true);
		MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(14.0f);
		mBaiduMap.setMapStatus(msu);
		LatLng cenpt = new LatLng(38.042258, 114.486270); // 地图的中心点
		// 设置缩放级别。
		mBaiduMap.setMapStatus(MapStatusUpdateFactory
				.newMapStatus(new MapStatus.Builder().target(cenpt).zoom(12)
						.build()));// 3-18
		/**
		 * 初始化覆盖层
		 */
		// initOverlay();
		// 初始化定位相关
		initLocation();
		
		// 初始化一下接口
		setOverLayList();

	}

	/**
	 * 初始化片区
	 */
	private void initVaulePianqu() {
		// new GetCityListAsyncTask(getActivity(), "12").execute("");

		mViewArray.add(viewPianqu);
		mViewArray.add(viewJuli);
		ArrayList<String> mTextArray = new ArrayList<String>();
		mTextArray.add("按片区");
		mTextArray.add("按距离");
		expandTabViewPianqu.setValue(mTextArray, mViewArray);
		expandTabViewPianqu.setTitle(mTextArray.get(0), 0);
		expandTabViewPianqu.setTitle(mTextArray.get(1), 1);

	}

	private void initLocation() {
		mBaiduMap = mMapView.getMap();
		// 开启定位图层 ---控制定位当前位置小图标是否显示
		mBaiduMap.setMyLocationEnabled(true);
		// 定位初始化
		mLocClient = new LocationClient(getActivity());
		mLocClient.registerLocationListener(myListener);
		LocationClientOption option = new LocationClientOption();
//		option.setOpenGps(true);// 打开gps
		option.setCoorType("bd09ll"); // 设置坐标类型
		option.setScanSpan(1000);// 每5s发起一次请求定位
		option.setIsNeedAddress(true);
//		option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);// 设置定位模式，这是高精度，需要开gps。我改成低功耗
		option.setLocationMode(LocationClientOption.LocationMode.Battery_Saving);//这种定位模式下，不会使用GPS，只会使用网络定位（Wi-Fi和基站定位）
		mLocClient.setLocOption(option);
		mLocClient.start();
	}

	/**
	 * 定位SDK监听函数
	 */
	public class MyLocationListenner implements BDLocationListener {

		@Override
		public void onReceiveLocation(BDLocation location) {
			// map view 销毁后不在处理新接收的位置
			if (location == null || mMapView == null)
				return;
			MyLocationData locData = new MyLocationData.Builder()
					.accuracy(location.getRadius())
					// 此处设置开发者获取到的方向信息，顺时针0-360
					.direction(100).latitude(location.getLatitude())
					.longitude(location.getLongitude()).build();

			mBaiduMap.setMyLocationData(locData);
			if (isFirstLoc) {
				isFirstLoc = false;
				LatLng ll = new LatLng(location.getLatitude(),
						location.getLongitude());
				AppConstant.NOWLATITUDE = location.getLatitude();
				AppConstant.NOWLONGITUDE = location.getLongitude();
				// TODO 获取到了定位信息，然后就可以获取到经纬度，然后调用接口查询附近的停车位

				MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);

				mBaiduMap.animateMapStatus(u);
				System.out.println("---------thc精度：" + location.getLongitude()
						+ ",纬度：" + location.getLatitude());
				new GetparkingListAsyncTask(getActivity(),
						AppConstant.NOWLONGITUDE + "", AppConstant.NOWLATITUDE
								+ "", getString(R.string.default_distance))
						.execute("");
			}
			tvCurrentLocation
					.setText(/* getString(R.string.tingche_current)+":"+ */location
							.getAddrStr());
			SharedPreferencesUtil.getInstance(getActivity()).putNowAddress(
					location.getAddrStr());
			mLocClient.stop();

			// 修改为自定义marker
			mCurrentMarker = BitmapDescriptorFactory
					.fromResource(R.drawable.icon_geo);
			mCurrentMode = LocationMode.NORMAL;
			mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(
					mCurrentMode, true, mCurrentMarker));
			rlCurrentLocation.setVisibility(View.VISIBLE);
			// 关闭定位图层---控制定位当前位置小图标是否显示
			// mBaiduMap.setMyLocationEnabled(false);
		}

		public void onReceivePoi(BDLocation poiLocation) {
		}
	}

	@Override
	public void setListener() {
		// TODO Auto-generated method stub
		mCommonTitleBar.setLeftView(getString(R.string.luduan),
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						/*
						 * if(HomeActivity.leftRightSlidingMenu != null){
						 * HomeActivity.leftRightSlidingMenu.showMenu(true); }
						 */
						Intent intent = new Intent(getActivity(),
								com.fanfanwang.ffw.app.ui.home.SectionAct.class);
						startActivity(intent);

					}
				});
		if (TextUtils.isEmpty(SharedPreferencesUtil.getInstance(getActivity())
				.getUserId())) {// 如果是null的话就显示登陆。
			mCommonTitleBar.setRightView(getString(R.string.login),
					new OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							/*
							 * if(HomeActivity.leftRightSlidingMenu != null){
							 * HomeActivity
							 * .leftRightSlidingMenu.showSecondaryMenu(); }
							 */
							// AppManager.getAppManager().finishAllActivity();
							Intent intent = new Intent(
									getActivity(),
									com.fanfanwang.ffw.app.ui.login.LoginAct.class);
							startActivity(intent);
						}
					});
		} else {
			mCommonTitleBar.setRightView(getString(R.string.yuyue_title),
					new OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							Intent intent = new Intent(getActivity(),
									ServiceYuYueListAct.class);
							startActivity(intent);
						}
					});
		}
		ivNetErrorReload.setOnClickListener(new OnClickListener() {

			@Override 
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (AppContext.instance.isNetworkConnected()) {
					// 网络可用加载数据
					llNetError.setVisibility(View.GONE);
					/**
					 * 初始化覆盖层
					 */
					//初始化片区和距离数据。
					//重新异步获取一下分区和距离的数据，然后设置数据。
					new GetLengthListAsyncTask(getActivity()).execute("");
					new GetCityListAsyncTask(getActivity(), "12").execute("");
					 initVaulePianqu();
				} else {
					// 网络不可用显示网络错误页面
					llNetError.setVisibility(View.VISIBLE);
				}
			}
		});

		btnTingcheLocation.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				initLocation();
			}
		});
		mBaiduMap.setOnMarkerClickListener(new OnMarkerClickListener() {
			public boolean onMarkerClick(final Marker marker) {
				// Button button = new Button(getActivity());
				// button.setBackgroundResource(R.drawable.popup);
				View tingcheOverViewLayout = null;
				OnInfoWindowClickListener listener = null;
				// if (marker == mMarkerA || marker == mMarkerD) {
				// tingcheOverViewLayout.setText("更改位置");
				listener = new OnInfoWindowClickListener() {
					public void onInfoWindowClick() {
						LatLng ll = marker.getPosition();
						// LatLng llNew = new LatLng(ll.latitude + 0.005,
						// ll.longitude + 0.005);
						// marker.setPosition(llNew);
						mBaiduMap.hideInfoWindow();
						// tingcheOverViewLayout= setOverView(ll);
						Intent mIntent = new Intent(getActivity(),
								SectionDetailAct.class);

						for (int i = 0; i < sectionLists.size(); i++) {
							if (Double.parseDouble(sectionLists.get(i).latitude) == (ll.latitude)
									&& Double.parseDouble(sectionLists.get(i).longitude) == (ll.longitude)) {
								ParkingListBean bean = sectionLists.get(i);
								mIntent.putExtra("id", bean.id);
								mIntent.putExtra("longitude1", bean.longitude);
								mIntent.putExtra("latitude1", bean.latitude);
								getActivity().startActivity(mIntent);
							}
						}

					}
				};
				LatLng ll = marker.getPosition();
				tingcheOverViewLayout = setOverView(ll);
				mInfoWindow = new InfoWindow(BitmapDescriptorFactory
						.fromView(tingcheOverViewLayout), ll, -47, listener);
				mBaiduMap.showInfoWindow(mInfoWindow);
				// }
				return true;
			}
		});
		viewPianqu.setOnSelectListener(new ViewMiddle.OnSelectListener() {

			@Override
			public void getValue(String cityid, String showText) {
				// TODO 点击片区之后的操作
				onRefreshPianQu(viewPianqu, cityid, showText);

			}
		});
		viewJuli.setOnSelectListener(new ViewRight.OnSelectListener() {

			@Override
			public void getValue(String distance, String showText) {
				onRefreshJuLi(viewJuli, showText);
			}
		});
	}

	/**
	 * 选中位置显示的弹出层 这里是往地图上填写数值的
	 * 
	 * @return
	 */
	private View setOverView(LatLng ll) {
		View tingcheOverViewLayout = inflater.inflate(
				R.layout.view_over_layout, null, false);
		ImageView ivTingcheIn = (ImageView) tingcheOverViewLayout
				.findViewById(R.id.ivTingcheIn);
		TextView tv_park_name = (TextView) tingcheOverViewLayout
				.findViewById(R.id.tv_park_name);
		TextView tv_null_count_value = (TextView) tingcheOverViewLayout
				.findViewById(R.id.tv_null_count_value);
		TextView tv_sum_count_value = (TextView) tingcheOverViewLayout
				.findViewById(R.id.tv_sum_count_value);
		for (int i = 0; i < sectionLists.size(); i++) {
			if (Double.parseDouble(sectionLists.get(i).latitude) == (ll.latitude)
					&& Double.parseDouble(sectionLists.get(i).longitude) == (ll.longitude)) {
				ParkingListBean bean = sectionLists.get(i);
				tv_park_name.setText(AppConstant.URLDecoderString(bean.name));
				tv_null_count_value.setText(AppConstant
						.URLDecoderString(bean.count));
				tv_sum_count_value.setText(AppConstant
						.URLDecoderString(bean.countnums));
			}
		}
		return tingcheOverViewLayout;
	}

	private void initOverlay() {
		// add marker overlay
		/*
		 * LatLng llA = new LatLng(39.963175, 116.400244); LatLng llB = new
		 * LatLng(39.942821, 116.369199); LatLng llC = new LatLng(39.939723,
		 * 116.425541); LatLng llD = new LatLng(39.906965, 116.401394);
		 * 
		 * OverlayOptions ooA = new MarkerOptions().position(llA).icon(bdA)
		 * .zIndex(9).draggable(true); mMarkerA = (Marker)
		 * (mBaiduMap.addOverlay(ooA)); OverlayOptions ooB = new
		 * MarkerOptions().position(llB).icon(bdA) .zIndex(5); mMarkerB =
		 * (Marker) (mBaiduMap.addOverlay(ooB)); OverlayOptions ooC = new
		 * MarkerOptions().position(llC).icon(bdA)
		 * .perspective(false).anchor(0.5f, 0.5f).rotate(30).zIndex(7); mMarkerC
		 * = (Marker) (mBaiduMap.addOverlay(ooC)); ArrayList<BitmapDescriptor>
		 * giflist = new ArrayList<BitmapDescriptor>(); giflist.add(bdA);
		 * giflist.add(bdA); giflist.add(bdA); OverlayOptions ooD = new
		 * MarkerOptions().position(llD).icons(giflist) .zIndex(0).period(10);
		 * mMarkerD = (Marker) (mBaiduMap.addOverlay(ooD));
		 */

		// add ground overlay
		// LatLng southwest = new LatLng(39.92235, 116.380338);
		// LatLng northeast = new LatLng(39.947246, 116.414977);
		// LatLngBounds bounds = new LatLngBounds.Builder().include(northeast)
		// .include(southwest).build();

		// OverlayOptions ooGround = new GroundOverlayOptions()
		// .positionFromBounds(bounds).image(bdGround).transparency(0.8f);
		// mBaiduMap.addOverlay(ooGround);
		//
		// MapStatusUpdate u = MapStatusUpdateFactory
		// .newLatLng(bounds.getCenter());
		// mBaiduMap.setMapStatus(u);

		mBaiduMap.setOnMarkerDragListener(new OnMarkerDragListener() {
			public void onMarkerDrag(Marker marker) {
			}

			public void onMarkerDragEnd(Marker marker) {
				ToastAlone.makeText(
						getActivity(),
						"拖拽结束，新位置：" + marker.getPosition().latitude + ", "
								+ marker.getPosition().longitude,
						Toast.LENGTH_LONG).show();
			}

			public void onMarkerDragStart(Marker marker) {
			}
		});
	}

	private void onRefreshJuLi(View view, String showText) {

		expandTabViewPianqu.onPressBack();
		int position = getPositon(view);
		// if (position >= 0 &&
		// !expandTabViewPianqu.getTitle(position).equals(showText)) {
		// expandTabViewPianqu.setTitle(showText, position);
		// }
		// ToastAlone.makeText(getActivity(), showText,
		// Toast.LENGTH_SHORT).show();
		// 调用接口重新获取数据
		if (showText.contains("千米")) {
			showText = showText.replaceAll("千米", "");
		}
		new GetparkingListAsyncTask(getActivity(), AppConstant.NOWLONGITUDE
				+ "", AppConstant.NOWLATITUDE + "", showText).execute("");

	}

	private void onRefreshPianQu(View view, String cityid, String showText) {

		expandTabViewPianqu.onPressBack();
		int position = getPositon(view);
		// if (position >= 0 &&
		// !expandTabViewPianqu.getTitle(position).equals(showText)) {
		// expandTabViewPianqu.setTitle(showText, position);
		// }
		// ToastAlone.makeText(getActivity(), showText,
		// Toast.LENGTH_SHORT).show();
		// 调用接口重新获取数据
		// if (showText.contains("千米")) {
		// showText = showText.replaceAll("千米", "");
		// }
		// new GetparkingListAsyncTask(getActivity(), AppConstant.NOWLONGITUDE
		// + "", AppConstant.NOWLATITUDE + "", showText).execute("");
		if (!TextUtils.isEmpty(cityid)) {
			// ToastAlone.makeText(getActivity(), cityid,
			// Toast.LENGTH_SHORT).show();
			new GetParkListAsyncTask(getActivity(), cityid).execute("");
		}

	}

	private int getPositon(View tView) {
		for (int i = 0; i < mViewArray.size(); i++) {
			if (mViewArray.get(i) == tView) {
				return i;
			}
		}
		return -1;
	}

	public void onBackPressed() {
		if (!expandTabViewPianqu.onPressBack()) {
			getActivity().finish();
		} else {
			exit();
		}

	}

	/**
	 * 是否启用缩放手势
	 * 
	 * @param v
	 */
	public void setZoomEnable(boolean b) {
		mUiSettings.setZoomGesturesEnabled(b);
	}

	/**
	 * 是否启用平移手势
	 * 
	 * @param v
	 */
	public void setScrollEnable(boolean b) {
		mUiSettings.setScrollGesturesEnabled(b);
	}

	/**
	 * 是否启用旋转手势
	 * 
	 * @param v
	 */
	public void setRotateEnable(boolean b) {
		mUiSettings.setRotateGesturesEnabled(b);
	}

	/**
	 * 是否启用俯视手势
	 * 
	 * @param v
	 */
	public void setOverlookEnable(boolean b) {
		mUiSettings.setOverlookingGesturesEnabled(b);
	}

	/**
	 * 是否启用指南针图层
	 * 
	 * @param v
	 */
	public void setCompassEnable(boolean b) {
		mUiSettings.setCompassEnabled(b);
	}

	/**
	 * 2s之内连续按两次退出程序的代码
	 */
	public void exit() {
		if ((System.currentTimeMillis() - AppContext.exitTime) > 2000) {
			Toast.makeText(context, getString(R.string.repress_exit),
					Toast.LENGTH_SHORT).show();
			AppContext.exitTime = System.currentTimeMillis();
		} else {
			try {
				com.fanfanwang.ffw.app.AppManager.getAppManager()
						.finishAllActivity();
				ActivityManager activityMgr = (ActivityManager) context
						.getSystemService(Context.ACTIVITY_SERVICE);
				activityMgr.killBackgroundProcesses(context.getPackageName());
				System.exit(0);
			} catch (Exception e) {
				System.exit(0);
			}
		}
	}

	/**
	 * 调用异步。接口实例化
	 */
	public void setInterface() {
		new GetLengthListAsyncTask(getActivity()).execute("");
		new GetCityListAsyncTask(getActivity(), "12").execute("");
		iGetLengthList = new IGetLengthList() {

			@Override
			public void getLengthList(ArrayList<LengthListBean> data) {
				// TODO Auto-generated method stub

				viewJuli.resetData(data);

			}
		};
		iGetCityList = new IGetCityList() {

			@Override
			public void getCityList(ArrayList<CityListBean> data) {
				viewPianqu.resetData(data);
			}
		};
	}

	public interface IGetLengthList {
		public void getLengthList(ArrayList<LengthListBean> data);
	}

	public interface IGetCityList {
		public void getCityList(ArrayList<CityListBean> data);
	}

	public interface IGetSectionList {
		public void setSectionList(ArrayList<ParkingListBean> beans);

		public void clearMarket();// 此方法是为了查询出来无结果的时候，清除地图的market使用的。

		public void getLocation();// 此方法是为了进入这个额页面就定位一次

		public void setRightView();// 设置页面的右边按钮显示预约记录。而不是登陆。
	}

	public void setOverLayList() {
		iGetSectionList = new IGetSectionList() {

			@Override
			public void setSectionList(ArrayList<ParkingListBean> beans) {
				sectionLists.clear();
				sectionLists.addAll(beans);
				mBaiduMap.clear();
				for (int i = 0; i < beans.size(); i++) {
					LatLng llA = new LatLng(
							Double.parseDouble(beans.get(i).latitude),
							Double.parseDouble(beans.get(i).longitude));
					OverlayOptions ooA = new MarkerOptions().position(llA)
							.icon(bdA).zIndex(9).draggable(true);// 最后一个表示是否拖拽，一定要设置icon否则会报错。
					Marker mMarkerA = (Marker) (mBaiduMap.addOverlay(ooA));
				}

			}

			@Override
			public void clearMarket() {
				// TODO Auto-generated method stub
				sectionLists.clear();
				mBaiduMap.clear();
			}

			@Override
			public void getLocation() {
				// TODO Auto-generated method stub
				initLocation();
				// initOverlay(); 这个添加覆盖物暂时不需要
			}

			@Override
			public void setRightView() {// 设置右边按钮的字显示预约记录。
				// TODO Auto-generated method stub
				if (mCommonTitleBar != null) {
					mCommonTitleBar.setRightView(
							getString(R.string.yuyue_title),
							new OnClickListener() {

								@Override
								public void onClick(View v) {
									// TODO Auto-generated method stub
									Intent intent = new Intent(getActivity(),
											ServiceYuYueListAct.class);
									startActivity(intent);
								}
							});
				}
			}

		};
	}

}
